package com.longy.gulimall.order.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.concurrent.ListenableFuture;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

@Slf4j
public class VisiableThreadPool extends ThreadPoolTaskExecutor {
    private void showInfo(String name){
        ThreadPoolExecutor executor = getThreadPoolExecutor();

        log.info("{}.TaskCount={}.CompletedTaskCount={}.ActiveCount={}.Queue={}.",name,executor.getTaskCount(),executor.getCompletedTaskCount(),executor.getActiveCount(),executor.getQueue().size());
    }

    @Override
    public void execute(Runnable task){
        showInfo("execute1");
        super.execute(task);
    }

    @Override
    public void execute(Runnable task,long statTime){
        showInfo("execute2");
        super.execute(task,statTime);
    }

    @Override
    public Future<?> submit(Runnable task){
        showInfo("submit1");
        return super.submit(task);
    }

    @Override
    public <T> Future<T> submit(Callable<T> task){
        showInfo("submit2");
        return super.submit(task);
    }

    @Override
    public ListenableFuture<?> submitListenable(Runnable task){
        showInfo("submitListenable");
        return super.submitListenable(task);
    }
}
